package com.deneme;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;

import functions.images.CommonHTML;
import functions.images.CommonHTML.PageName;

public class PuzzleConfiguration extends HttpServlet {
    private static BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

    public void doPost(HttpServletRequest req,
			HttpServletResponse resp)
					throws IOException {
    	doGet(req, resp);
    }

    public void doGet(HttpServletRequest req,
			HttpServletResponse resp)
					throws IOException {
    	BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
    	
    	/* create output page with puzzle config form */
    	PrintWriter out = resp.getWriter();
    	out.write("<html>\n" +
    			"	<head>\n" +
				"		<link rel=\"stylesheet\" href=\"/styles.css\" type=\"text/css\" />\n" +
    			"		<title>Make a new puzzle!</title>\n" +
    			"	</head>\n" +
    			"	<body>\n" +
    			"		<div class='content'>" +
    			CommonHTML.getNavBar(PageName.none) + // includes menu bar at top of page 
    			"		<div class='puzzle_config_form'>\n" +
    			"		<form action='/savepuzzle' method='post'>\n" +
    			"			<input type='hidden' name='config' />\n" + 
    			"			<input type='hidden' name='savetouser' value='false' />\n" +
    			"			<input type='hidden' name='blobkey' value='" + blobKey.getKeyString() + "' />\n" +
    			"			<label for='dimension'>Dimension:</label>" +
    			"			<select id='dimension' name='dimension'>\n" +
    			"				<option value='2'>2 x 2</option>\n" +
    			"				<option value='3'>3 x 3</option>\n" +
    			"				<option value='4'>4 x 4</option>\n" +
    			"				<option value='5'>5 x 5</option>\n" +
    			"				<option value='6'>6 x 6</option>\n" +
    			"				<option value='7'>7 x 7</option>\n" +
    			"				<option value='8'>8 x 8</option>\n" +
    			"				<option value='9'>9 x 9</option>\n" +
    			"				<option value='10'>10 x 10</option>\n" +
    			"			</select><br />\n" +
    			"			<label for='difficulty'>Difficulty:</label>" +
    			"			<input type='radio' id='difficulty'name='difficulty' value='easy' />Easy\n" +
    			"			<input type='radio' name='difficulty' value='medium' />Medium\n" +
    			"			<input type='radio' name='difficulty' value='hard' />Hard\n" +
    			// this secrethard value is in case the user doesn't select a difficulty.  this is our easter egg
    			"			<input class='invisible' type='radio' name='difficulty' value='secrethard' checked />\n" +
    			"			<br /><input type='submit' class='fun_button' value='Play!' />" +
    			"		</form>\n" +
    			"		<img src='/serve?blob-key=" + blobKey.getKeyString() + "' />" +
    			"		</div><!-- puzzle_config_form -->" +
    					"</div><!-- content -->\n" +
    			"	</body>\n" +
    			"</html>\n");
    }

}
